﻿
    using Chain.BLL;
//    using ChainStock.Controls;
    using System;
    using System.Data;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    public partial class RptShop : PageBase
    {

        private int MemCount;
        private decimal MemMoney;

        private decimal sumFRechargeMoney;
        private decimal sumOrderDiscountMoney;
        private int sumOrderPoint;
        private decimal sumOrderTotalMoney;
        private int sumPointNumber;
        private decimal sumSRechargeMoney;


        private void BindList(DataTable dt)
        {
            this.gvRptShop.DataSource = dt;
            this.gvRptShop.DataBind();
            PageBase.BindSerialRepeater(this.gvRptShop, 0);
        }

        protected void btnShopExcel_Click(object sender, EventArgs e)
        {
            DataExcelInfo.ShopReportExcel(this.Get_ParameterList(this.QueryCondition()), base._UserName);
        }

        protected void btnShopSearch_Click(object sender, EventArgs e)
        {
            DataTable dt = this.Get_ParameterList(this.QueryCondition());
            this.BindList(dt);
        }

        private DataTable Get_ParameterList(string strSql)
        {
            SysShop bllShop = new SysShop();
            strSql = PubFunction.GetShopAuthority(base._UserShopID, "ShopID", strSql);
            string strStartTime = "";
            string strEndTime = "";
            if (this.txtStartTime.Value == "")
            {
                strStartTime = DateTime.Now.AddYears(-50).ToString("yyyy-MM-dd");
            }
            else
            {
                strStartTime = Convert.ToDateTime(this.txtStartTime.Value).AddSeconds(1.0).ToString();
            }
            if (this.txtEndTime.Value == "")
            {
                strEndTime = DateTime.Now.AddYears(50).ToString("yyyy-MM-dd");
            }
            else
            {
                strEndTime = PubFunction.TimeEndDay(this.txtEndTime.Value).ToString();
            }
            return bllShop.getTotalShop(strStartTime, strEndTime, new string[] { strSql }).Tables[0];
        }

        protected void gvRptShop_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
            {
                string OrderTotalMoney = DataBinder.Eval(e.Item.DataItem, "sumOrderTotalMoney").ToString().Trim();
                if (!OrderTotalMoney.Equals(""))
                {
                    this.sumOrderTotalMoney += Convert.ToDecimal(OrderTotalMoney);
                }
                string OrderDiscountMoney = DataBinder.Eval(e.Item.DataItem, "sumOrderDiscountMoney").ToString().Trim();
                if (!OrderDiscountMoney.Equals(""))
                {
                    this.sumOrderDiscountMoney += Convert.ToDecimal(OrderDiscountMoney);
                }
                string SRechargeMoney = DataBinder.Eval(e.Item.DataItem, "sumSRechargeMoney").ToString().Trim();
                if (!SRechargeMoney.Equals(""))
                {
                    this.sumSRechargeMoney += Convert.ToDecimal(SRechargeMoney);
                }
                string FRechargeMoney = DataBinder.Eval(e.Item.DataItem, "sumFRechargeMoney").ToString().Trim();
                if (!FRechargeMoney.Equals(""))
                {
                    this.sumFRechargeMoney += Convert.ToDecimal(FRechargeMoney);
                }
                string OrderPoint = DataBinder.Eval(e.Item.DataItem, "sumOrderPoint").ToString().Trim();
                if (!OrderPoint.Equals(""))
                {
                    this.sumOrderPoint += Convert.ToInt32(OrderPoint);
                }
                string PointNumber = DataBinder.Eval(e.Item.DataItem, "sumPointNumber").ToString().Trim();
                if (!PointNumber.Equals(""))
                {
                    this.sumPointNumber += Convert.ToInt32(PointNumber);
                }
                string Count = DataBinder.Eval(e.Item.DataItem, "MemCount").ToString().Trim();
                if (!Count.Equals(""))
                {
                    this.MemCount += Convert.ToInt32(Count);
                }
                string Money = DataBinder.Eval(e.Item.DataItem, "MemMoney").ToString().Trim();
                if (!Money.Equals(""))
                {
                    this.MemMoney += Convert.ToDecimal(Money);
                }
            }
            if (e.Item.ItemType == ListItemType.Footer)
            {
                if (e.Item.FindControl("lblSumOrderTotalMoney") != null)
                {
                    Label lblSumOrderTotalMoney = (Label) e.Item.FindControl("lblSumOrderTotalMoney");
                    lblSumOrderTotalMoney.Text = this.sumOrderTotalMoney.ToString("0.00");
                }
                if (e.Item.FindControl("lblSumOrderDiscountMoney") != null)
                {
                    Label lblSumOrderDiscountMoney = (Label) e.Item.FindControl("lblSumOrderDiscountMoney");
                    lblSumOrderDiscountMoney.Text = this.sumOrderDiscountMoney.ToString("0.00");
                }
                if (e.Item.FindControl("lblSumSRechargeMoney") != null)
                {
                    Label lblSumSRechargeMoney = (Label) e.Item.FindControl("lblSumSRechargeMoney");
                    lblSumSRechargeMoney.Text = this.sumSRechargeMoney.ToString("0.00");
                }
                if (e.Item.FindControl("lblSumFRechargeMoney") != null)
                {
                    Label lblSumFRechargeMoney = (Label) e.Item.FindControl("lblSumFRechargeMoney");
                    lblSumFRechargeMoney.Text = this.sumFRechargeMoney.ToString("0.00");
                }
                if (e.Item.FindControl("lblSumOrderPoint") != null)
                {
                    Label lblSumOrderPoint = (Label) e.Item.FindControl("lblSumOrderPoint");
                    lblSumOrderPoint.Text = this.sumOrderPoint.ToString();
                }
                if (e.Item.FindControl("lblSumPointNumber") != null)
                {
                    Label lblSumPointNumber = (Label) e.Item.FindControl("lblSumPointNumber");
                    lblSumPointNumber.Text = this.sumPointNumber.ToString();
                }
                if (e.Item.FindControl("lblMemCount") != null)
                {
                    Label lblMemCount = (Label) e.Item.FindControl("lblMemCount");
                    lblMemCount.Text = this.MemCount.ToString();
                }
                if (e.Item.FindControl("lblMemMoney") != null)
                {
                    Label lblMemMoney = (Label) e.Item.FindControl("lblMemMoney");
                    lblMemMoney.Text = this.MemMoney.ToString();
                }
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                PubFunction.BindShopSelect(base._UserShopID, this.sltShop, 0, base._UserShopID != 1);
                this.txtStartTime.Value = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("yyyy-MM-dd");
                this.txtEndTime.Value = DateTime.Now.ToString("yyyy-MM-dd");
                if ((PubFunction.curParameter.dataAuthority != 0) && (base._UserShopID > 1))
                {
                    this.sltShop.Value = this._UserShopID.ToString();
                    this.sltShop.Attributes.Add("disabled", "disabled");
                }
                DataTable dt = this.Get_ParameterList(this.QueryCondition());
                this.BindList(dt);
            }
        }

        protected string QueryCondition()
        {
            string strMemShopID = this.sltShop.Value;
            StringBuilder strSql = new StringBuilder();
            strSql.Append("ShopID>0 ");
            if (strMemShopID != "")
            {
                strSql.AppendFormat("and ShopID={0}", int.Parse(strMemShopID));
            }
            return strSql.ToString();
        }
    }


